Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Content is read if ContentLength Header is null #27

Merged
merged 1 commit into from
Feb 13, 2024

Conversation

b-rad15
Copy link
Contributor

@b-rad15 b-rad15 commented Feb 11, 2024

This fixes an error that content of an error is not read if the ContentLength Header is null. Content must be read before checking the content length header. Brings the error handling in line with the success handling that also checks against 0.

I have tested this on the same code that produced the error in #26 and it now functions correctly. More tests would likely to be helpful to add to catch errors like this in future or other errors that exist with the same condition elsewhere in the code but I wouldn't know where to start with that.

@@ -651,7 +651,7 @@ void IRestCustomizable.RemoveCustomization(RestRequestCustomization customizatio
}

// See if we have a JSON error to get some more details from
if (response.Content.Headers.ContentLength is not > 0)
if (response.Content.Headers.ContentLength == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat of a nitpick, but shouldn't this be is 0 for style/consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you, I was matching line 589 further up in the file that uses the same pattern. Whatever is decided on though I think those 2 checks should probably match.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, stick to the same as the other check - we can do a pass over constants + pattern matching later.

@b-rad15
Copy link
Contributor Author

b-rad15 commented Feb 12, 2024

I guess I missed the analyzer tests when I was running it locally. The tests seem like they were failing because of this issue dotnet/roslyn-sdk#1099 (comment), changing it to the non *.Xunit packages and switching to DefaultVerifier like it suggests fixes the immediate issues but results in the following error:

System.InvalidOperationException
Mismatch between number of diagnostics returned, expected "1" actual "5"

Where the 4 extra diagnostics are all like this:

Diagnostics:
// error CS1705: Assembly 'Remora.Rest.Core' with identity 'Remora.Rest.Core, Version=2.2.1.0, Culture=neutral, PublicKeyToken=null' uses 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

Not sure where that package came from or how to fix that though

@Nihlus
Copy link
Member

Nihlus commented Feb 12, 2024

Ah, nice catch - can you open a separate pull request to fix that issue?

@b-rad15 b-rad15 mentioned this pull request Feb 13, 2024
@Nihlus Nihlus merged commit fd0333f into Remora:main Feb 13, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants